<script setup lang="ts">
interface DataItem {
    title: string;
    useravatar: string;
}

// 这里通过接口获取

const data: DataItem[] = [
    {
        title: '购买了化妆品',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
    {
        title: '购买了好多化妆品',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"

    },
    {
        title: '购买了好多化妆品',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
    {
        title: '购买了化妆品12',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
    {
        title: '购买了化妆品14',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
    {
        title: '购买了化妆品1223',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
    {
        title: '购买了化妆品345',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
    {
        title: 'Ant Design Title 8',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
    {
        title: 'Ant Design Title 9',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
    {
        title: 'Ant Design Title 10',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
    {
        title: 'Ant Design Title 11',
        useravatar: "http://localhost:8080/src/assets/user_avatar.jpg"
    },
];
</script>

<template>
    <div class="fatherDiv">

        <div class="sonDiv">
            <li class="list" v-for="item in data">
                <span class="useravatar_style_list">
                    <img :src="item.useravatar" alt="">
                </span>
                <span class="user_product_style">{{ item.title }}</span>
            </li>
        </div>
        <div class="sonDiv">
            <li class="list" v-for="item in data">
                <span class="useravatar_style_list">
                    <img :src="item.useravatar" alt="">
                </span>
                <span class="user_product_style">{{ item.title }}</span>
            </li>
        </div>
    </div>
</template>

<style lang="scss">
.fatherDiv {

    height: 100%;

    width: 100%;

    overflow: hidden;

    .sonDiv {

        animation: myAnimation 10s infinite linear;

        width: 100%;

        list-style: none;

        li {
            cursor: pointer;
            width: 80%;
            /* 调整列表项宽度 */
            max-width: 400px;
            /* 设置最大宽度，根据需要调整 */
            margin: 10px auto;
            /* 居中并调整上下间距 */
            padding: 10px;
            background-color: #f5f5f5;
            /* 背景色，根据需要调整 */
            border-radius: 8px;
            /* 圆角，根据需要调整 */
            display: flex;
            align-items: center;
            justify-content: space-between;
            /* 头像和文字之间的空间分配 */

            .useravatar_style_list {
                width: 40px;
                /* 调整头像宽度 */
                height: 40px;
                /* 调整头像高度 */
                border-radius: 50%;
                /* 圆形头像 */
                overflow: hidden;
                /* 裁剪头像超出的部分 */
            }

            .useravatar_style_list img {
                width: 100%;
                height: 100%;
                object-fit: cover;
                /* 保持图片比例，裁剪不变形 */
            }

            .user_product_style {
                flex: 1;
                /* 自动填充剩余空间 */
                margin-left: 10px;
                /* 调整文字与头像之间的间距 */
                overflow: hidden;
                /* 超出部分省略号显示 */
                white-space: nowrap;
                /* 不换行 */
                text-overflow: ellipsis;
                /* 超出部分显示省略号 */
            }


            &:hover {
                background-color: #e0e0e0;
                /* 鼠标悬停时的背景色 */
                animation-play-state: paused;
            }
        }

    }

}

@keyframes myAnimation {
    from {
        transform: translate(0px, 0%);
    }

    to {
        transform: translate(0px, -100%);
    }
}
</style>